﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ISO
{
    class Player : Character
    {
        #region Constants
        private int CENTER = 15;
        #endregion

        #region Variables
        public enum Actions
        {
            MoveN = 0, MoveNE = 1, MoveE = 2, MoveSE = 3, MoveS = 4, MoveSW = 5, MoveW = 6, MoveNW = 7
        };
        private Keys[] _keybinds;
        #endregion

        #region Attributes
        #endregion

        #region Constructors
        public Player(int _starting_x_index, int _starting_y_index, Texture2D _texture):
            base(_starting_x_index, _starting_y_index, _texture, 100, 10)
        {
            _keybinds = new Keys[8];
            _keybinds[(int)Actions.MoveN] = Keys.W;
            _keybinds[(int)Actions.MoveE] = Keys.D;
            _keybinds[(int)Actions.MoveS] = Keys.S;
            _keybinds[(int)Actions.MoveW] = Keys.A;
        }
        #endregion

        #region Methods
        public void Move(Map _current_map)
        {
            KeyboardState _key = Keyboard.GetState();

            if (_key.IsKeyDown(_keybinds[(int)Actions.MoveN]))
            {
                if (_current_map.CurrentTiles[1] > 0 &&
                    (int)Y_Index - _current_map.CurrentTiles[1] == CENTER)
                {
                    Y_Offset += 0.125;
                    _current_map.CurrentTiles[1] -= (int)Y_Offset;
                    Y_Index -= (int)Y_Offset;
                }
                else
                {
                    if (Y_Index > 0)
                        Y_Index -= 0.125;
                }
            }
            else if (_key.IsKeyDown(_keybinds[(int)Actions.MoveE]))
            {
                if (_current_map.CurrentTiles[0] <= _current_map.Num_Total_Per_Row - _current_map.Num_Visible_Per_Row - 1 &&
                    (int)(X_Index-_current_map.CurrentTiles[0]) == CENTER)
                {
                    X_Offset += 0.125;
                    _current_map.CurrentTiles[0] += (int)X_Offset;
                    X_Index += (int)X_Offset;
                }
                else
                {
                    if (X_Index-_current_map.CurrentTiles[0] < _current_map.Num_Visible_Per_Row-1)
                        X_Index += 0.125;
                }
            }
            else if (_key.IsKeyDown(_keybinds[(int)Actions.MoveS]))
            {
                if (_current_map.CurrentTiles[1] <= _current_map.Num_Total_Per_Row - _current_map.Num_Visible_Per_Row - 1 &&
                    (int)Y_Index - _current_map.CurrentTiles[1] == CENTER)
                {
                    Y_Offset += 0.125;
                    _current_map.CurrentTiles[1] += (int)Y_Offset;
                    Y_Index += (int)Y_Offset;
                }
                else
                {
                    if (Y_Index - _current_map.CurrentTiles[1] < _current_map.Num_Visible_Per_Row-1)
                        Y_Index += 0.125;
                }
            }
            else if (_key.IsKeyDown(_keybinds[(int)Actions.MoveW]))
            {
                if (_current_map.CurrentTiles[0] > 0 &&
                    (int)X_Index - _current_map.CurrentTiles[0] == CENTER)
                {
                    X_Offset += 0.125;
                    _current_map.CurrentTiles[0] -= (int)X_Offset;
                    X_Index -= (int)X_Offset;
                }
                else
                {
                    if (X_Index > 0)
                        X_Index -= 0.125;
                }
            }
            if (X_Offset >= 1 || X_Offset <= -1)
                X_Offset = 0;
            if (Y_Offset >= 1 || Y_Offset <= -1)
                Y_Offset = 0;

        }
        #endregion

    }
}
